package com.app.Activity;

import java.util.ArrayList;

import com.app.Controller.NetworkController;
import com.app.Custom.ListWorkRatingAdapter;
import com.app.Custom.WorkRating;
import com.app.Network.Protocol;

import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;
import app.com.ModuleRole.R;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.SlidingDrawer;

public class frmDanhGiaActivity extends Activity implements RatingBar.OnRatingBarChangeListener{
	ArrayList<WorkRating> array;
	ListWorkRatingAdapter arrayAdapter;
	int port = Protocol.PORT;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_danh_gia);
		Log.d("PEERDROID","Da vao frm_Danh_Gia");
		
		//Lay ID & tat Notification
		NotificationManager mn=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        mn.cancel(getIntent().getExtras().getInt("ID"));
		
		//Khoi tao ArrayList & ListWorkAdapter
        array = new ArrayList<WorkRating>();
        arrayAdapter = new ListWorkRatingAdapter(this, R.layout.list_rating, array);
               
        //Tao listView cho danh sach Danh gia
        final ListView list = (ListView)findViewById(R.id.listView);
        list.setAdapter(arrayAdapter);
        
        final WorkRating work = new WorkRating("Hoang An");
        array.add(0,work);
        WorkRating workrat = new WorkRating("Quoc phu");
        array.add(1,workrat);
        WorkRating workra = new WorkRating("Thanh Truc");
        array.add(2,workra);
        
        arrayAdapter.notifyDataSetChanged();
        
        //Khai bao & bat su kien Button send Result Danh Gia
        final Button btnOK = (Button)findViewById(R.id.btnOK);
        btnOK.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d("PEERDROID", String.valueOf(array.get(0).getRating()));
				String result= "";
				for(int i=0; i<array.size(); i++){
					result +=  array.get(i).getTxtusername() + "/" + array.get(i).getRating() + ";";
				}
				Log.d("PEERDROID","xem result khi click OK "+result);
				NetworkController.sendResultDanhGia("192.168.1.77:" + port, result);
				frmDanhGiaActivity.this.finish();
				
			}
		});
	}

	@Override
	public void onRatingChanged(RatingBar ratingBar, float rating,
			boolean fromUser) {
		// TODO Auto-generated method stub
	}


}
